
package com.dc.gameserver.serverCore.controller.handleController;

import com.dc.gameserver.proto.gameserverprotoVo.playerIdRequest;
import com.dc.gameserver.proto.gameserverprotoVo.playerIdResponse;
import com.dc.gameserver.serverCore.controller.AbstractController.AbstractController;
import com.dc.gameserver.serverCore.controller.AbstractController.IController;
import com.dc.gameserver.serverCore.service.character.PlayerInstance;
import com.dc.gameserver.serverCore.service.managerService.PlayerManagerService;
import com.google.protobuf.MessageLite;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author  石头哥哥
 *         Project : LandlordsServer
 *         Date: 13-6-4
 *         Time: 上午11:49
 *         Connect: 13638363871@163.com
 *         packageName: Server.ServerCore.Controller
 *         登录成功之后，玩家请求在线玩家的编号列表：playerID
 */
@Service
public class playerIdController extends AbstractController {

    /**
     */
    @Override
    public void PostConstruct() {
       int ID= playerIdRequest.msgID.ID_VALUE;
       GAME_CONTROLLERS[ID]=this;   //业务逻辑处理引用
       IController.MESSAGE_LITE[ID]= playerIdRequest.getDefaultInstance();   //解析的pb实体类型
    }

     /**
     * messageLite数据结构体分发
     *
     * @param messageLite
     * @param player
     * @throws Exception
     */
    @Override
    public void DispatchMessageLit(MessageLite messageLite, PlayerInstance player) throws Exception {
        //返回ipList
        playerIdResponse.Builder builder= playerIdResponse.newBuilder();
        List<Integer> idlist=PlayerManagerService.getPlayerIDList(player);
        if (idlist!=null){
            builder.addAllIDList(idlist);
        }
        player.DirectSend(wrappedBufferShort(playerIdResponse.msgID.ID_VALUE, builder.build()));

    }
}
